package cn.legend.travel.comment.controller;

import cn.legend.travel.comment.pojo.param.InsertCommentParam;
import cn.legend.travel.comment.pojo.vo.CommentListItemVO;
import cn.legend.travel.comment.service.CommentService;
import cn.legend.travel.common.pojo.authentication.CurrentPrincipal;
import cn.legend.travel.common.pojo.vo.PageData;
import cn.legend.travel.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/comments")
@Validated
@Api(tags = "3. 评论管理")
public class CommentController {

    @Autowired
    private CommentService commentService;


    @PostMapping("/addProductComment")
    @ApiOperation("发表产品评论")
    @ApiOperationSupport(order = 100)
    public JsonResult insertProductComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                    @Valid InsertCommentParam InsertCommentParam) {
        commentService.insertProductComment(currentPrincipal, InsertCommentParam);
        return JsonResult.ok();
    }

    @PostMapping("/addDelicacyComment")
    @ApiOperation("发表产品评论")
    @ApiOperationSupport(order = 100)
    public JsonResult insertDelicacyComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                    @Valid InsertCommentParam InsertCommentParam) {
        commentService.insertDelicacyComment(currentPrincipal, InsertCommentParam);
        return JsonResult.ok();
    }
    @PostMapping("/addDestinationComment")
    @ApiOperation("发表产品评论")
    @ApiOperationSupport(order = 100)
    public JsonResult insertDestinationComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                    @Valid InsertCommentParam InsertCommentParam) {
        commentService.insertDestinationComment(currentPrincipal, InsertCommentParam);
        return JsonResult.ok();
    }
    @PostMapping("/addGuideComment")
    @ApiOperation("发表产品评论")
    @ApiOperationSupport(order = 100)
    public JsonResult insertGuideComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                    @Valid InsertCommentParam InsertCommentParam) {
        commentService.insertGuideComment(currentPrincipal, InsertCommentParam);
        return JsonResult.ok();
    }
    @PostMapping("/addHotelComment")
    @ApiOperation("发表产品评论")
    @ApiOperationSupport(order = 100)
    public JsonResult insertHotelComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                    @Valid InsertCommentParam InsertCommentParam) {
        commentService.insertHotelComment(currentPrincipal, InsertCommentParam);
        return JsonResult.ok();
    }
    @PostMapping("/addReviewComment")
    @ApiOperation("发表产品评论")
    @ApiOperationSupport(order = 100)
    public JsonResult insertReviewComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                    @Valid InsertCommentParam InsertCommentParam) {
        commentService.insertReviewComment(currentPrincipal, InsertCommentParam);
        return JsonResult.ok();
    }
    @PostMapping("/addSceneryComment")
    @ApiOperation("发表产品评论")
    @ApiOperationSupport(order = 100)
    public JsonResult insertSceneryComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                    @Valid InsertCommentParam InsertCommentParam) {
        commentService.insertSceneryComment(currentPrincipal, InsertCommentParam);
        return JsonResult.ok();
    }

    @GetMapping("/listByGuide")
    @ApiOperation("根据文章查询评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "guideId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult listByArticle(@Range(message = "请提交有效的文章ID值！") Long articleId,
                                    @Range(min = 1, message = "请提交有效的页码值！") Integer page) {
        Integer pageNum = page == null ? 1 : page;
        PageData<CommentListItemVO> pageData = commentService.listByArticle(articleId, pageNum);
        return JsonResult.ok(pageData);
    }

    @GetMapping("/listByDelicacy")
    @ApiOperation("根据美食查询评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "美食ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult listByDelicacy(@Range(message = "请提交有效的美食ID值！") Long delicacyId,
                                    @Range(min = 1, message = "请提交有效的页码值！") Integer page) {
        Integer pageNum = page == null ? 1 : page;
        PageData<CommentListItemVO> pageData = commentService.listByDelicacy(delicacyId, pageNum);
        return JsonResult.ok(pageData);
    }

    @GetMapping("/listByDestination")
    @ApiOperation("根据目的地查询评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "destinationId", value = "目的地ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult listByDestination(@Range(message = "请提交有效的目的地ID值！") Long destinationId,
                                     @Range(min = 1, message = "请提交有效的页码值！") Integer page) {
        Integer pageNum = page == null ? 1 : page;
        PageData<CommentListItemVO> pageData = commentService.listByDestination(destinationId, pageNum);
        return JsonResult.ok(pageData);
    }

    @GetMapping("/listByHotel")
    @ApiOperation("根据酒店查询评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hotelId", value = "酒店ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult listByHotel(@Range(message = "请提交有效的酒店ID值！") Long hotelId,
                                     @Range(min = 1, message = "请提交有效的页码值！") Integer page) {
        Integer pageNum = page == null ? 1 : page;
        PageData<CommentListItemVO> pageData = commentService.listByHotel(hotelId, pageNum);
        return JsonResult.ok(pageData);
    }

    @GetMapping("/listByProduct")
    @ApiOperation("根据产品查询评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productId", value = "产品ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult listByProduct(@Range(message = "请提交有效的产品ID值！") Long productId,
                                     @Range(min = 1, message = "请提交有效的页码值！") Integer page) {
        Integer pageNum = page == null ? 1 : page;
        PageData<CommentListItemVO> pageData = commentService.listByProduct(productId, pageNum);
        return JsonResult.ok(pageData);
    }


    @GetMapping("/listByReview")
    @ApiOperation("根据点评查询评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reviewId", value = "点评ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult listByReview(@Range(message = "请提交有效的点评ID值！") Long reviewId,
                                     @Range(min = 1, message = "请提交有效的页码值！") Integer page) {
        Integer pageNum = page == null ? 1 : page;
        PageData<CommentListItemVO> pageData = commentService.listByReview(reviewId, pageNum);
        return JsonResult.ok(pageData);
    }

    @GetMapping("/listByScenery")
    @ApiOperation("根据景点查询评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult listByScenery(@Range(message = "请提交有效的景点ID值！") Long sceneryId,
                                     @Range(min = 1, message = "请提交有效的页码值！") Integer page) {
        Integer pageNum = page == null ? 1 : page;
        PageData<CommentListItemVO> pageData = commentService.listByScenery(sceneryId, pageNum);
        return JsonResult.ok(pageData);
    }
    @GetMapping("getProductSecondComments")
    @ApiOperation("得到二级产品评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult getProductSecondComments(Long commentId, Integer pageNum) {
        return JsonResult.ok(commentService.getProductSecondComments(commentId, pageNum));
    }
    @GetMapping("getScenerySecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult getScenerySecondComments(Long commentId, Integer pageNum) {
        return JsonResult.ok(commentService.getScenerySecondComments(commentId, pageNum));
    }
    @GetMapping("getReviewSecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult getReviewSecondComments(Long commentId, Integer pageNum) {
        return JsonResult.ok(commentService.getReviewSecondComments(commentId, pageNum));
    }
    @GetMapping("getHotelSecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult getHotelSecondComments(Long commentId, Integer pageNum) {
        return JsonResult.ok(commentService.getHotelSecondComments(commentId, pageNum));
    }
    @GetMapping("getDelicacySecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult getDelicacySecondComments(Long commentId, Integer pageNum) {
        return JsonResult.ok(commentService.getDelicacySecondComments(commentId, pageNum));
    }
    @GetMapping("getGuideSecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult getGuideSecondComments(Long commentId, Integer pageNum) {
        return JsonResult.ok(commentService.getGuideSecondComments(commentId, pageNum));
    }
    @GetMapping("getDestinationSecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult getDestinationSecondComments(Long commentId, Integer pageNum) {
        return JsonResult.ok(commentService.getDestinationSecondComments(commentId, pageNum));
    }
    @PostMapping("deleteDestinationSecondComments")
    @ApiOperation("删除评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult deleteDestinationComments(Long commentId) {
        commentService.deleteDestinationComments(commentId);
        return JsonResult.ok();
    }
    @PostMapping("deleteProductSecondComments")
    @ApiOperation("得到二级产品评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult deleteProductSecondComments(Long commentId) {
        commentService.deleteProductSecondComments(commentId);
        return JsonResult.ok();
    }
    @PostMapping("deleteScenerySecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult deleteScenerySecondComments(Long commentId) {
        commentService.deleteScenerySecondComments(commentId);
        return JsonResult.ok();
    }
    @PostMapping("deleteReviewSecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult deleteReviewSecondComments(Long commentId) {
        commentService.deleteReviewSecondComments(commentId);
        return JsonResult.ok();
    }
    @PostMapping("deleteHotelSecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult deleteHotelSecondComments(Long commentId) {
        commentService.deleteHotelSecondComments(commentId);
        return JsonResult.ok();
    }
    @PostMapping("deleteDelicacySecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult deleteDelicacySecondComments(Long commentId) {
        commentService.deleteDelicacySecondComments(commentId);
        return JsonResult.ok();
    }
    @PostMapping("deleteGuideSecondComments")
    @ApiOperation("得到二级评论列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "文章ID", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult deleteGuideSecondComments(Long commentId) {
        commentService.deleteGuideSecondComments(commentId);
        return JsonResult.ok();
    }
}
